package com.heima;

import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
import java.io.File;

public class OCRDemo {
    public static void main(String[] args) {
        File imageFile = new File("D:\\JavaProject\\heima-leadnews\\heima-leadnews-test\\ocr-demo\\src\\main\\resources\\images\\dog.jpeg");
        ITesseract instance = new Tesseract();
        instance.setDatapath("D:/tessdata"); // 替换为你的 tessdata 目录路径
        instance.setLanguage("chi_sim"); // 设置识别语言为简体中文
        try {
            String result = instance.doOCR(imageFile);
           // result = result.replaceAll("\\r|\\n","-").replaceAll(" ","");
            System.out.println(result);
        } catch (TesseractException e) {
            System.err.println(e.getMessage());
        }
    }
}
